#define _CRT_SECURE_NO_WARNINGS 1
#include<stdio.h>
#include<stdlib.h>

void getmax(int* color,int* max) {
	if (*max < color[0])*max = color[1];
	if (*max < color[1])*max = color[1];
	if (*max < color[2])*max = color[2];
}

int main() {
	int color[3] = { 0,0,0 };
	int input[1000];
	int top = 0;
	while (1) {
		scanf("%d", &input[top++]);
		if (getchar() == '\n')break;
	}

	int N;
	scanf("%d", &N);

	int max=0;
	for (int i = 0; i < N; i++)color[input[i]]++;
	getmax(color, &max);

	for (int i = N; i < top; i++) {
		color[input[i]]++;
		color[input[i - N]]--;
		getmax(color, &max);
	}
	printf("%d", max);
	return 0;
	

}